import request from "@/utils/request"

export enum EquipmentStatus {
  未安装 = 1,
  安装中 = 2,
  启用 = 3,
  禁用 = 4,
  '维修/维护' = 5,
  报废 = 6,
}

export enum EquipmentType {
  直流 = 1,
  交流 = 2,
}

export enum GunStatus {
  // 故障 = '02',
  // 离线 = '05',
  // 占用 = '0B',
  // 充电中 = '01',
  // 空闲 = '00',
  // 其他 = '99',
  空闲 = '00',
  插枪空闲 = '0B',
  离线 = '05',
  故障 = '02',
  充电中 = '01',
  充电后占位 = '09',
  其他 = '99',
}

export const GunStatusColorMap: Record<string, string> = {
  [GunStatus.故障]: '#fa5b06',
  [GunStatus.离线]: '#919090',
  [GunStatus.插枪空闲]: '#1890ff',
  [GunStatus.空闲]: '#1890ff',
  [GunStatus.充电中]: '#22B573',
  [GunStatus.充电后占位]: '#fdb900',
  [GunStatus.其他]: '#c7c7c7',
}

export interface QueryEquipmentListParams extends PaginationParams {
  /** 电站名称 */
  stationTitle?: string
  /** 设备类型 */
  stubType?: EquipmentType
  /** 设备ID */
  equipmentId?: string
  isStock?: number
  /** 设备名称 */
  stubName?: string
  /** 设备状态 */
  status?: EquipmentStatus
}

export enum VinStatus {
  支持 = 1,
  不支持 = 2,
}

export interface Equipment {
  createTime: number
  iccid: string
  /** 设备编号 */
  id: string
  kw: number
  latitude: number
  longitude: number
  name: string
  orgId:string
  stationId: string
  stationName: string
  /** 设备状态 */
  status: EquipmentStatus
  /** 设备类型 */
  type: EquipmentType
  vinStatus: VinStatus
  operationId: string
}

export async function queryEquipmentList(params: QueryEquipmentListParams) {
  return request<Equipment[]>('/app/manager/equipment/list', {
    data: params,
  })
}

export async function editEquipment(params: Partial<Equipment>) {
  return request('/app/manager/equipment/addOrUpdate', {
    data: params,
  })
}

export enum StubStatus {
  启用 = 1,
  禁用 = 2,
}

export enum StubType {
  国标2015 = 1,
  国标2011 = 2,
}

export interface QueryStubListParams extends PaginationParams {
  /** 设备 id */
  equipmentId?: string
}

export interface Stub {
  createTime: number
  /** 设备编号 */
  id: string
  orgId:string
  orgName:string
  kw: number
  name: string
  stationId: string
  current:number
  stationName: string
  equipmentId: string
  /** 设备状态 */
  status: StubStatus
  /** 额定电压下限 */
  voltageBegin: number
  /** 额定电压上限 */
  voltageEnd: number
  /** 枪标准 */
  standardType: StubType
  operationId: string
  /** 二维码地址 */
  scanCode: string
}

export async function queryStubList(params: QueryStubListParams) {
  return request<Stub[]>('/app/manager/stub/list', {
    data: params,
  })
}

export async function editStub(params: Partial<Stub>) {
  return request('/app/manager/stub/addOrUpdateStub', {
    data: params,
  })
}
